<template>
  <div class="avatar-upload-modal">
    <div class="modal-content">
      <h3>上传新头像</h3>
      <input type="file" @change="handleFileChange" accept="image/*">
      <div class="modal-actions">
        <button @click="$emit('close')">取消</button>
        <button @click="uploadAvatar" :disabled="!selectedFile">上传</button>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue';

const selectedFile = ref(null);

const handleFileChange = (e) => {
  selectedFile.value = e.target.files[0];
};

const uploadAvatar = () => {
  // 这里应该是上传逻辑
  // 模拟上传成功
  const avatarUrl = URL.createObjectURL(selectedFile.value);
  emit('upload-success', avatarUrl);
};

const emit = defineEmits(['close', 'upload-success']);
</script>

<style scoped>
.avatar-upload-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.modal-content {
  background: white;
  padding: 20px;
  border-radius: 8px;
  width: 400px;
  max-width: 90%;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

button {
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
}
</style>